HD = ../80m.img

ASM = nasm
DASM = objdump
CC = gcc
LD = ld
ASMFLAGS = -I ../include/ -f elf32
CFLAGS = -I ../include/ -c -fno-builtin -m32 -fno-stack-protector -Wall
LDFLAGS = -Ttext 0x1000 -m elf_i386
DASMFLAGS = -D
LIB = ../lib/orangescrt.a
BIN = echo pwd

.PHONY : everything final clean realclean disasm all install

everything : $(BIN)

install : all clean
	cp ../kernel.bin ./ -v
	tar vcf inst.tar kernel.bin $(BIN)
	dd if=inst.tar of=$(HD) seek=`echo "obase=10;ibase=16;(\`egrep -e '^ROOT_BASE' ../boot/include/load_inc.asm | sed -e 's/.*0x//g'\`+\`egrep -e '#define[[:space:]]*INSTALL_START_SECT' ../include/sys/config.h | sed -e 's/.*0x//g'\`)*200" | bc` bs=1 count=`ls -l inst.tar | awk -F " " '{print $$5}'` conv=notrunc
	
all : realclean everything

final : all clean

clean :
	rm -fr *.o
	
realclean :
	rm -f $(BIN) *.o
	
kernel.bin:
	cp ../kernel.bin ./
	
start.o : start.asm
	$(ASM) $(ASMFLAGS) -o $@ $<
	
echo.o: echo.c ../include/type.h ../include/stdio.h
	$(CC) $(CFLAGS) -o $@ $<
	
echo : echo.o start.o $(LIB)
	$(LD) $(LDFLAGS) -o $@ $?
	
pwd.o: pwd.c ../include/type.h ../include/stdio.h
	$(CC) $(CFLAGS) -o $@ $<

pwd : pwd.o start.o $(LIB)
	$(LD) $(LDFLAGS) -o $@ $?